/* Copyright (c) 2024 Huawei Technologies Co., Ltd.
openFuyao is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */
import '@/styles/log.less';
import { Tooltip } from 'antd';
import { ResponseCode } from '@/common/constants';
import { QuestionCircleOutlined } from '@ant-design/icons';
import { getLogCollectionData, getLogJobTime } from '@/api/containerLogApi';
import { useEffect, useState } from 'openinula';

export default function LogCollecting() {
  const [collectData, setCollectData] = useState([]);
  const [collectAge, setCollectAge] = useState('');
  const [collectTime, setCollectTime] = useState('');
  const getLogCollection = async () => {
    const res = await getLogCollectionData();
    if (res.status === ResponseCode.OK) {
      setCollectData(res.data.data[Object.keys(res.data.data)[0]]);
    }
  };
  const getLogCollectionTime = async () => {
    const res = await getLogJobTime();
    if (res.status === ResponseCode.OK) {
      if (!res.data.data.TableManager.RetentionDeletesEnabled) {
        setCollectTime('无限制');
      } else {
        setCollectTime(res.data.data.TableManager.RetentionPeriod);
      }
      setCollectAge(res.data.data.LimitsConfig.RejectOldSamplesMaxAge);
    };
  };
  useEffect(() => {
    getLogCollection();
    getLogCollectionTime();
  }, []);
  return (
    <div className='logCollecting'>
      <p className='logCollecting_title'>日志采集源</p>
      {collectData.map(item => (
        <div className='logCollecting_info'>
          <p className='logCollecting_info_title'>{item.name}</p>
          <p className='logCollecting_info_path'>采集路径 <span className='logCollecting_info_address'>{item.mountPath}</span></p>
        </div>
      ))}
      <p className='logCollecting_title logCollecting_title_time'>日志保存时长</p>
      <div className='logCollecting_time'>
        <p className='logCollecting_time_title'>已采集日志样本保留最大时长：</p>
        <Tooltip title='日志被采集后存储的最大时间，超过该值后日志将会被删除。'>
          <QuestionCircleOutlined style={{ color: '#89939B' }} />
        </Tooltip>
        <p className='logCollecting_time_num'>{collectTime}</p>
      </div>
      <div className='logCollecting_time'>
        <p className='logCollecting_time_title'>日志采集可接受最大样本年龄：</p>
        <Tooltip title='日志从产生到被采集的可接受时间范围，超过该值日志将不会被采集。'>
          <QuestionCircleOutlined style={{ color: '#89939B' }} />
        </Tooltip>
        <p className='logCollecting_time_num'>{collectAge}</p>
      </div>
    </div>
  );
}
